<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/11/22
 * Time: 09:05
 */

namespace app\modules\dataMapper;

use Yii;
use yii\helpers\ArrayHelper;

class UserRepository
{
    /**
     * 获取用户信息
     *
     * @date   2018/11/22
     * @author edmmss
     * @param $userId
     * @return array|false
     * @throws \yii\db\Exception
     */
    public function getUserInfo($userId)
    {
        // 这里不考虑如sql注入之类的
        $user = Yii::$app->data_mapper_db
            ->createCommand("SELECT * FROM shop_user WHERE id = {$userId}")
            ->queryAll();

        return $user ? ArrayHelper::index($user, 'id') : [];
    }
}